package kaizone.haining.chaobohui.json;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONObject;

public class Banner {
	
    public static final String INDEX = "index";
    public static final String SMALL = "small";
    public static final String BIG = "big";
    public static final String BOTTOM = "bottom";
	public static final String BANNERID = "bannerId";
	public static final String GMTCREATE = "gmtCreate";
	public static final String GMTMODIFIED = "gmtModified";
	public static final String ID = "id";
	public static final String MEMO = "memo";
	public static final String PICMODELS = "picModels";
	
	public static final String CLICKURL = "clickUrl";
	public static final String NAME = "name";
	public static final String PICPATH = "picPath";
	public static final String PICURL = "picUrl";
	public static final String PICURL100X000 = "picUrl100x000";
	
	private int bannerId;
	private String gmtCreate;
	private String gmtModified;
	private int id;
	private String memo;
	private List<PicModel> picModels;
	
	public int getBannerId() {
		return bannerId;
	}

	public void setBannerId(int bannerId) {
		this.bannerId = bannerId;
	}

	public String getGmtCreate() {
		return gmtCreate;
	}

	public void setGmtCreate(String gmtCreate) {
		this.gmtCreate = gmtCreate;
	}

	public String getGmtModified() {
		return gmtModified;
	}

	public void setGmtModified(String gmtModified) {
		this.gmtModified = gmtModified;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getMemo() {
		return memo;
	}

	public void setMemo(String memo) {
		this.memo = memo;
	}

	public List<PicModel> getPicModels() {
		return picModels;
	}

	public void setPicModels(List<PicModel> picModels) {
		this.picModels = picModels;
	}
	
	public static Banner parse(JSONObject jsonObject){
		Banner banner = new Banner();
		banner.setBannerId(jsonObject.optInt(BANNERID));
		banner.setGmtCreate(jsonObject.optString(GMTCREATE));
		banner.setGmtModified(jsonObject.optString(GMTMODIFIED));
		banner.setId(jsonObject.optInt(ID));
		banner.setMemo(jsonObject.optString(MEMO));
		JSONArray jsonPicModes = jsonObject.optJSONArray(PICMODELS);
		if(jsonPicModes != null){
			ArrayList<PicModel> picModels = new ArrayList<Banner.PicModel>();
            int picmodesLen = jsonPicModes.length();
            for (int j = 0; j < picmodesLen; j++) {
            	JSONObject jsonPicmodeObj = jsonPicModes.optJSONObject(j);
            	PicModel picModel = PicModel.parse(jsonPicmodeObj);
            	picModels.add(picModel);
            }
            banner.setPicModels(picModels);
		}
		return banner;
	}

	public static class PicModel{
		public String clickUrl;
		public String name;
		public String picPath;
		public String picUrl;
		public String picUrl100x000;
		
		public static PicModel parse(JSONObject jsonObject){
			PicModel picModel = new PicModel();
			picModel.clickUrl = jsonObject.optString(CLICKURL);
			picModel.name = jsonObject.optString(NAME);
			picModel.picPath = jsonObject.optString(PICPATH);
			picModel.picUrl = jsonObject.optString(PICURL);
			picModel.picUrl100x000 = jsonObject.optString(PICURL100X000);
			return picModel;
		}
	}
	
	

}
